package socket

import (
	"github.com/goccy/go-json"
	"zsgGin/utils/socket/models"
)

// WsMessage 消息转换
type WsMessage struct {
		MessageType  int
		MessageData []byte
}

func NewWsMessage(messageType int, messageData []byte) *WsMessage {
	return &WsMessage{MessageType: messageType, MessageData: messageData}
}

//把前端传过来的json解析为 command
func (w *WsMessage)parseForCmd() (*models.WsResponse,error) {
		cmd:=&WsCommand{}
		err:=json.Unmarshal(w.MessageData,cmd)
		if err!=nil{
			return nil,err
		}
		//绑定到具体的model,返回数据
		return  cmd.Parse()
}


